<template>
  <view class="card-game">
    <!-- 游戏状态栏 -->
    <view class="game-status-bar">
      <view class="round-info">
        <text class="round-text">第{{ currentRound }}轮 / {{ maxRounds }}轮</text>
        <text class="phase-text">{{ getPhaseText() }}</text>
      </view>
      <view class="timer-info" v-if="gamePhase === 'play'">
        <text class="timer-text">{{ timeRemaining }}秒</text>
      </view>
    </view>
    
    <!-- AI角色区域 -->
    <view class="ai-character-area">
      <view class="ai-avatar-large">
        <image :src="aiAvatar" class="ai-avatar-img" mode="aspectFill"></image>
        <view class="ai-emotion-badge" :class="aiEmotion">
          <text class="emotion-text">{{ getEmotionText() }}</text>
        </view>
      </view>
      <view class="ai-info">
        <text class="ai-name">{{ aiName }}</text>
        <text class="ai-trust">信任等级: {{ Math.floor(aiTrustLevel) }}</text>
      </view>
    </view>
    
    <!-- 玩家手牌区域 -->
    <view class="player-hand-area" v-if="gamePhase === 'play'">
      <view class="hand-title">
        <text class="hand-text">你的手牌</text>
        <text class="hand-count">{{ playerHand.length }}张</text>
      </view>
      <view class="cards-container">
        <view 
          v-for="card in playerHand" 
          :key="card.id"
          class="card-item"
          :class="[card.type, card.rarity, { disabled: !canPlayCard(card) }]"
          @click="playCard(card)"
        >
          <view class="card-icon">{{ card.icon }}</view>
          <text class="card-name">{{ card.name }}</text>
          <text class="card-description">{{ card.description }}</text>
          <view class="card-cost" v-if="card.cost > 0">
            <text class="cost-text">💰{{ card.cost }}</text>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 游戏结果区域 -->
    <view class="game-result-area" v-if="gamePhase === 'feedback'">
      <view class="result-content">
        <text class="result-title">轮次结果</text>
        <view class="result-stats">
          <text class="stat-item">信任值: {{ playerTrust }}</text>
          <text class="stat-item">金币: {{ playerGold }}</text>
          <text class="stat-item">AI信任: {{ Math.floor(aiTrustLevel) }}</text>
        </view>
      </view>
    </view>
    
    <!-- 游戏结束界面 -->
    <view class="game-end-area" v-if="gamePhase === 'ended'">
      <view class="end-content">
        <text class="end-title">游戏结束</text>
        <view class="final-stats">
          <text class="final-stat">最终信任值: {{ playerTrust }}</text>
          <text class="final-stat">最终金币: {{ playerGold }}</text>
          <text class="final-stat">使用信任卡: {{ playerStats.trustCardsUsed }}张</text>
          <text class="final-stat">使用欺骗卡: {{ playerStats.deceptionCardsUsed }}张</text>
        </view>
        <button class="restart-btn" @click="restartGame">重新开始</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'CardGame',
  props: {
    currentRound: {
      type: Number,
      default: 1
    },
    maxRounds: {
      type: Number,
      default: 5
    },
    gamePhase: {
      type: String,
      default: 'draw'
    },
    timeRemaining: {
      type: Number,
      default: 10
    },
    aiAvatar: {
      type: String,
      default: '/static/logo.png'
    },
    aiName: {
      type: String,
      default: 'AI'
    },
    aiEmotion: {
      type: String,
      default: 'neutral'
    },
    aiTrustLevel: {
      type: Number,
      default: 50
    },
    playerHand: {
      type: Array,
      default: () => []
    },
    playerTrust: {
      type: Number,
      default: 0
    },
    playerGold: {
      type: Number,
      default: 0
    },
    playerStats: {
      type: Object,
      default: () => ({
        trustCardsUsed: 0,
        deceptionCardsUsed: 0,
        defenseCardsUsed: 0,
        totalGoldEarned: 0,
        totalTrustEarned: 0
      })
    }
  },
  methods: {
    getPhaseText() {
      const phaseTexts = {
        'draw': '抽牌阶段',
        'play': '出牌阶段',
        'resolve': '结算阶段',
        'feedback': '反馈阶段'
      }
      return phaseTexts[this.gamePhase] || '未知阶段'
    },
    
    getEmotionText() {
      const emotionTexts = {
        'neutral': '😐 平静',
        'trusting': '😊 信任',
        'suspicious': '🤔 怀疑',
        'angry': '😠 愤怒'
      }
      return emotionTexts[this.aiEmotion] || '😐 平静'
    },
    
    canPlayCard(card) {
      // 检查卡牌是否可以使用
      if (this.gamePhase !== 'play') return false
      if (this.timeRemaining <= 0) return false
      if (this.playerGold < card.cost) return false
      
      return true
    },
    
    playCard(card) {
      this.$emit('play-card', card)
    },
    
    restartGame() {
      this.$emit('restart-game')
    }
  }
}
</script>

<style scoped>
.card-game {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20rpx;
  gap: 20rpx;
}

.game-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, rgba(0, 123, 255, 0.1), rgba(0, 123, 255, 0.2));
  border-radius: 12rpx;
  border: 1rpx solid rgba(0, 123, 255, 0.3);
}

.round-info {
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.round-text {
  font-size: 18rpx;
  font-weight: bold;
  color: #007bff;
}

.phase-text {
  font-size: 14rpx;
  color: #666;
}

.timer-info {
  padding: 8rpx 16rpx;
  background: rgba(255, 59, 48, 0.1);
  border-radius: 20rpx;
  border: 1rpx solid rgba(255, 59, 48, 0.3);
}

.timer-text {
  font-size: 16rpx;
  font-weight: bold;
  color: #ff3b30;
}

.ai-character-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16rpx;
  padding: 20rpx;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 16rpx;
  border: 1rpx solid rgba(0, 0, 0, 0.1);
}

.ai-avatar-large {
  width: 100rpx;
  height: 100rpx;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  border: 3rpx solid rgba(0, 123, 255, 0.3);
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.ai-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.ai-emotion-badge {
  position: absolute;
  top: -8rpx;
  right: -8rpx;
  padding: 4rpx 8rpx;
  border-radius: 12rpx;
  font-size: 12rpx;
  font-weight: bold;
  border: 2rpx solid rgba(255, 255, 255, 0.9);
}

.ai-emotion-badge.trusting {
  background: linear-gradient(135deg, #28a745, #20c997);
  color: white;
}

.ai-emotion-badge.suspicious {
  background: linear-gradient(135deg, #ffc107, #ffb300);
  color: #333;
}

.ai-emotion-badge.angry {
  background: linear-gradient(135deg, #dc3545, #c82333);
  color: white;
}

.ai-emotion-badge.neutral {
  background: linear-gradient(135deg, #6c757d, #5a6268);
  color: white;
}

.emotion-text {
  font-size: 10rpx;
}

.ai-info {
  text-align: center;
}

.ai-name {
  font-size: 20rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 4rpx;
}

.ai-trust {
  font-size: 14rpx;
  color: #666;
  padding: 4rpx 12rpx;
  background: rgba(0, 123, 255, 0.1);
  border-radius: 12rpx;
  border: 1rpx solid rgba(0, 123, 255, 0.3);
}

.player-hand-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.hand-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8rpx;
}

.hand-text {
  font-size: 18rpx;
  font-weight: bold;
  color: #333;
}

.hand-count {
  font-size: 14rpx;
  color: #666;
  background: rgba(0, 123, 255, 0.1);
  padding: 4rpx 12rpx;
  border-radius: 12rpx;
  border: 1rpx solid rgba(0, 123, 255, 0.3);
}

.cards-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12rpx;
  justify-content: center;
}

.card-item {
  width: 140rpx;
  height: 180rpx;
  border-radius: 12rpx;
  padding: 12rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8rpx;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.card-item:active {
  transform: scale(0.95);
}

.card-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card-item.disabled:active {
  transform: none;
}

/* 卡牌类型样式 */
.card-item.trust {
  background: linear-gradient(135deg, rgba(40, 167, 69, 0.1), rgba(40, 167, 69, 0.2));
  border: 2rpx solid rgba(40, 167, 69, 0.3);
}

.card-item.deception {
  background: linear-gradient(135deg, rgba(220, 53, 69, 0.1), rgba(220, 53, 69, 0.2));
  border: 2rpx solid rgba(220, 53, 69, 0.3);
}

.card-item.defense {
  background: linear-gradient(135deg, rgba(0, 123, 255, 0.1), rgba(0, 123, 255, 0.2));
  border: 2rpx solid rgba(0, 123, 255, 0.3);
}

.card-item.event {
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.1), rgba(255, 193, 7, 0.2));
  border: 2rpx solid rgba(255, 193, 7, 0.3);
}

/* 卡牌稀有度样式 */
.card-item.common {
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.card-item.rare {
  box-shadow: 0 4rpx 12rpx rgba(0, 123, 255, 0.3);
}

.card-item.epic {
  box-shadow: 0 6rpx 16rpx rgba(255, 193, 7, 0.4);
}

.card-icon {
  font-size: 32rpx;
  margin-bottom: 4rpx;
}

.card-name {
  font-size: 14rpx;
  font-weight: bold;
  color: #333;
  text-align: center;
  line-height: 1.2;
}

.card-description {
  font-size: 10rpx;
  color: #666;
  text-align: center;
  line-height: 1.3;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-cost {
  position: absolute;
  top: 8rpx;
  right: 8rpx;
  background: rgba(255, 193, 7, 0.9);
  color: #333;
  padding: 2rpx 6rpx;
  border-radius: 8rpx;
  font-size: 10rpx;
  font-weight: bold;
}

.cost-text {
  font-size: 10rpx;
}

.game-result-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40rpx;
}

.result-content {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 30rpx;
  border-radius: 16rpx;
  border: 1rpx solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.result-title {
  font-size: 24rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 20rpx;
}

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.stat-item {
  font-size: 16rpx;
  color: #666;
  padding: 8rpx 16rpx;
  background: rgba(0, 123, 255, 0.1);
  border-radius: 8rpx;
  border: 1rpx solid rgba(0, 123, 255, 0.3);
}

.game-end-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40rpx;
}

.end-content {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 40rpx;
  border-radius: 16rpx;
  border: 1rpx solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.end-title {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 24rpx;
}

.final-stats {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
  margin-bottom: 30rpx;
}

.final-stat {
  font-size: 18rpx;
  color: #666;
  padding: 12rpx 20rpx;
  background: rgba(0, 123, 255, 0.1);
  border-radius: 12rpx;
  border: 1rpx solid rgba(0, 123, 255, 0.3);
}

.restart-btn {
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  border: none;
  border-radius: 12rpx;
  padding: 16rpx 32rpx;
  font-size: 18rpx;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 4rpx 12rpx rgba(0, 123, 255, 0.3);
}

.restart-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2rpx 8rpx rgba(0, 123, 255, 0.4);
}

/* 移动端优化 */
@media (max-width: 768rpx) {
  .card-game {
    padding: 12rpx;
    gap: 12rpx;
  }
  
  .game-status-bar {
    padding: 12rpx;
  }
  
  .round-text {
    font-size: 16rpx;
  }
  
  .phase-text {
    font-size: 12rpx;
  }
  
  .timer-text {
    font-size: 14rpx;
  }
  
  .ai-character-area {
    padding: 12rpx;
    gap: 8rpx;
  }
  
  .ai-avatar-large {
    width: 60rpx;
    height: 60rpx;
  }
  
  .ai-name {
    font-size: 16rpx;
  }
  
  .ai-trust {
    font-size: 12rpx;
  }
  
  .hand-text {
    font-size: 16rpx;
  }
  
  .hand-count {
    font-size: 12rpx;
  }
  
  .cards-container {
    gap: 8rpx;
  }
  
  .card-item {
    width: 100rpx;
    height: 140rpx;
    padding: 8rpx;
  }
  
  .card-icon {
    font-size: 24rpx;
  }
  
  .card-name {
    font-size: 12rpx;
  }
  
  .card-description {
    font-size: 8rpx;
  }
  
  .result-content {
    padding: 24rpx;
  }
  
  .result-title {
    font-size: 20rpx;
  }
  
  .stat-item {
    font-size: 14rpx;
  }
  
  .end-content {
    padding: 32rpx;
  }
  
  .end-title {
    font-size: 24rpx;
  }
  
  .final-stat {
    font-size: 16rpx;
  }
  
  .restart-btn {
    padding: 14rpx 28rpx;
    font-size: 16rpx;
  }
}
</style>

